import { createApp} from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import router from "@/router";
import "bootstrap/scss/bootstrap.scss"
import axios from "axios";
import VueAxios from 'vue-axios'

import auth from '../utils/auth'
import loading from "../utils/loading";
import FlyLoading from "../utils/loading";

// config
const BASE_URL = 'http://127.0.0.1:8000/'


const app = createApp(App)

app.use(router)
app.use(ElementPlus)
app.use(VueAxios,axios);

axios.interceptors.request.use(config => {

    config.baseURL = BASE_URL
    config.headers.Authorization = "JWT " + auth.token

    return config
})

axios.interceptors.response.use(response => {

    if(response.status === 403){
        auth.clearUserAndToken()
        router.replace('/login').then(r => {
            console.log("ERR")
        })
    }

    return response
})

app.config.globalProperties.$auth = auth
app.config.globalProperties.$flyLoading = FlyLoading

app.mount('#app')
